# -*- coding: ISO-8859-1 -*-

import wx
import sys


to_float= (lambda x: x/100.0)
to_int= (lambda x: int(x*100))

class GASettingsDialog(wx.Dialog):
	def __init__(self,p):
		
		self.project = p #same as the project in main window
		wx.Dialog.__init__(self, None, -1, 'GA Options', size=(558, 408))
		
		okButton = wx.Button(self, wx.ID_OK, "OK", pos=(387, 353))
		self.Bind(wx.EVT_BUTTON, self.OnButton, okButton)
		cancelButton = wx.Button(self, wx.ID_CANCEL, "Cancel", pos=(470, 353))
		wx.StaticLine(self, -1, pos=(4, 343), size=(542, 2))
		
		### MAKE PAINELS
		pop=self.project.population #already a list :) [size_pop]
		run = self.project.parameters[2]
		self.populationPanel = PopulationPanel(self, pos=(196, 4), size=(349, 333),stuf_list=pop,runs = run)
		
		select_params=self.project.parent_selection ##[callable_string, range(arity),range(num_contestants), range(losers_hype)]
		self.tourneamentPanel = TourneamentPanel(self, pos=(196, 4), size=(349, 333),stuf_list=select_params)
		self.selectionPanel = SelectionPanel(self, pos=(196, 4), size=(349, 333),stuf_list=select_params)
		
		recomb_params = self.project.crossover ##crossover = [callable_string, range(prob), range(numPoints), range(weight)]
		self.recombinationParametersPanel= RecombinationParametersPanel(self, pos=(196, 4), size=(349, 333),stuf_list=recomb_params)
		self.recombinationPanel = RecombinationPanel(self, pos=(196, 4), size=(349, 333),stuf_list=recomb_params)
		
		mutate_params = self.project.mutation ##mutation = [callable_string, range(Prob), range(alpha), range(sigma)]
		is_ag = self.project.parameters[1]=="GA"
		self.mutationPanel = MutationPanel(self, pos=(196, 4), size=(349, 333),stuf_list=mutate_params,ag=is_ag)
		
		selects_params = self.project.survivor_selection
		self.survivorSelectionPanel = SurvivorSelectionPanel(self, pos=(196, 4), size=(349, 333),stuf_list=selects_params)
		#######
		
		self.data = (("Project",		self.populationPanel),
				("Parent Selection",	self.selectionPanel),
				("Tournament",		self.tourneamentPanel),
				("Crossover",	self.recombinationPanel),
				("Crossover Param",	self.recombinationParametersPanel),
				("Mutation",		self.mutationPanel),
				("Survivor Selection",	self.survivorSelectionPanel))
		
		for i,panel in self.data:
			panel.Hide()
		
		self.MakeLeftList(self.data)

	def MakeLeftList(self,data):
		
		self.list = wx.ListBox(self, -1, (4, 4), (182, 333), [], wx.LB_SINGLE)
		for label, panel in data:
			self.list.Append(label, panel)
		
		self.Bind(wx.EVT_LISTBOX, self.OnListBoxItemSelected, self.list)


	def OnListBoxItemSelected(self, event):
		list = event.GetEventObject()
		panel = list.GetClientData(list.GetSelection())
		
		for i,otherPanel in self.data:
			if otherPanel != None:
				otherPanel.Show(otherPanel == panel) #so mostra o selected
	
	def OnButton(self,event):
		## POP!
		print "\tON BUTTON: POPULATION",self.populationPanel.GetValues()
		self.project.population=self.populationPanel.GetValues()[0] # [range(pop)]//ranged values from pop
		self.project.parameters[2]=self.populationPanel.GetValues()[1] # [range(pop)]//ranged values from pop
		self.project.parameters[0]="Longshot"
		## SELECT PARENTS
		self.project.parent_selection = self.selectionPanel.GetValues() # stuf_list = [callable_string, [range(arity),range(num_contestants), range(losers_hype)]]
		## RECOMBINATION
		self.project.crossover = self.recombinationPanel.GetValues()
		## MUTATION
		print "\tON BUTTON: MUTATION",self.mutationPanel.GetValues()
		self.project.mutation= self.mutationPanel.GetValues()
		## SELECT SURVIVORS
		self.project.survivor_selection = self.survivorSelectionPanel.GetValues()
		
		self.project.create_config_file(first_write=False) #rewrite project
		self.EndModal(0) #close conf window


class PopulationPanel(wx.Panel):
	def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER, name=wx.PanelNameStr,stuf_list=[-1],runs = -1):
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		box = wx.StaticBox(self, -1,"Population Size", pos=(0, 5), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,32,17,17)				# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,60,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],60,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		## check if it's a long shot or not
		## if not from and to have the same value and jumps = 0
		## else calculadt the list range values and put them in the spins
		d,a,j = list_to_val(stuf_list)
		
		wx.StaticText(self, -1, "From", pos=(s1[0],s1[1]))
		self.spinPopSizeMin = wx.SpinCtrl(self, -1, "20", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinPopSizeMin.SetRange(1,99999)
		self.spinPopSizeMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinPopSizeMax = wx.SpinCtrl(self, -1, "20", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinPopSizeMax.SetRange(1,99999)
		self.spinPopSizeMax.SetValue(a)
		wx.StaticText(self, -1, "with step:", pos=(s3[0],s3[1]))
		self.spinPopSizeJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinPopSizeJumps.SetRange(0,999)
		self.spinPopSizeJumps.SetValue(j)
		
		
		box = wx.StaticBox(self, -1,"Number of Runs", pos=(0, 66+15), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,66+15+27,50,17)			# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,80,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],20,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		
		## check if it's a long shot or not
		## if not from and to have the same value and jumps = 0
		## else calculadt the list range values and put them in the spins
		wx.StaticText(self, -1, "Number of Runs", pos=(s1[0],s1[1]))
		self.spinRuns = wx.SpinCtrl(self, -1, "", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinRuns.SetRange(1,9999)
		self.spinRuns.SetValue(runs)
		wx.StaticText(self, -1, "times", pos=(s2[0],s2[1]))

	
	def GetValues(self):
		list = val_to_list(self.spinPopSizeMin.GetValue(),self.spinPopSizeMax.GetValue(),self.spinPopSizeJumps.GetValue())
		## print "------------------------------------------>",self.spinRuns.GetValue()
		return (list,self.spinRuns.GetValue())


class SelectionPanel(wx.Panel):
	def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER, name=wx.PanelNameStr,stuf_list=[-1]):
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		self.parent=parent #bah ...!
		print "\n\tinit selection -->",stuf_list
		self.sel_type=stuf_list[0]
		
		### TIPO SELECCAO
		# stuf_list = [callable_string, [range(arity),range(num_contestants), range(losers_hype)]]
		box = wx.StaticBox(self, -1, "Metodo", pos=(0, 0), size=(348, 138))
		
		self.radioAUE = wx.RadioButton(self, -1, "Universal Stochastic Sampling", style = wx.RB_GROUP, pos=(10, 19))
		self.radioRoleta = wx.RadioButton(self, -1, "Roulette", pos=(10, 42))
		self.radioRanking = wx.RadioButton(self, -1, "Ranking linear", pos=(10, 65))
		self.radioRanking2 = wx.RadioButton(self, -1, "Ranking exponential", pos=(10, 88))
		self.radioTorneio = wx.RadioButton(self, -1, "Tournament", pos=(10, 111))
		
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioAUE)
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioRoleta)
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioRanking)
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioTorneio)
		
		if self.sel_type=="stochastic_universal_sampling_select":
			self.radioAUE.SetValue(True)
			self.set_tourneament(False)
		if self.sel_type=="roulette_select":
			self.radioRoleta.SetValue(True)
			self.set_tourneament(False)
		if self.sel_type=="order_select_linear":
			self.radioRanking.SetValue(True)
			self.set_tourneament(False)
		if self.sel_type=="order_select_exponential":
			self.radioRanking.SetValue(True)
			self.set_tourneament(False)
		if self.sel_type=="tournament_select":
			self.radioTorneio.SetValue(True)
			self.set_tourneament(True)
			
		
		
		### ARIDADE
		box = wx.StaticBox(self, -1, "Arity", pos=(0, 145), size=(348, 80))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,168,100,17)					# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)			# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])		# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])		# size reference to sp1, 50 is the sizeX needed for this one
		s3=(s1[0]+6,s1[1]+s1[3]+13,40,s1[3])	# in the other line - you go down by adding the size of the text and delta (in this case 4 (cause of the spins) and half of the line1 position)  to the first line position
		sp3=(s3[0]+s3[2],s3[1]-2,50,sp1[3])		#equal to sp2
		
		d,a,j = list_to_val(stuf_list[1])
		
		wx.StaticText(self, -1, "Number of Parents:", pos=(s1[0],s1[1]))
		self.spinArityMin = wx.SpinCtrl(self, -1, "2", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinArityMin.SetRange(1,999)
		self.spinArityMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinArityMax = wx.SpinCtrl(self, -1, "2", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinArityMax.SetRange(1,999)
		self.spinArityMax.SetValue(a)
		wx.StaticText(self, -1, "step:", pos=(s3[0],s3[1]))
		self.spinArityJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinArityJumps.SetRange(0,999)
		self.spinArityJumps.SetValue(j)
		
		
		### HIGHT PROB
		box = wx.StaticBox(self, -1, "Higher Probabilities", pos=(0, 230), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,253,50,17)				# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,60,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],60,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],35,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		if stuf_list[4]==[None]:
			d,a,j = 0,0,0
		else:
			d,a,j = map(to_int,list_to_val(stuf_list[4]))
		
		wx.StaticText(self, -1, "Varying:", pos=(s1[0],s1[1]))
		self.spinHightProbMin = wx.SpinCtrl(self, -1, "2", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinHightProbMin.SetRange(0,100)
		self.spinHightProbMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinHightProbMax = wx.SpinCtrl(self, -1, "2", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinHightProbMax.SetRange(0,100)
		self.spinHightProbMax.SetValue(a)
		wx.StaticText(self, -1, "step:", pos=(s3[0],s3[1]))
		self.spinHightProbJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinHightProbJumps.SetRange(0,100)
		self.spinHightProbJumps.SetValue(j)
		
		
		
	
	def set_tourneament(self,tf):
		self.parent.tourneamentPanel.spinFightersMin.Enable(tf)
		self.parent.tourneamentPanel.spinFightersMax.Enable(tf)
		self.parent.tourneamentPanel.spinFightersJumps.Enable(tf)
		self.parent.tourneamentPanel.spinLoosersHypeMin.Enable(tf)
		self.parent.tourneamentPanel.spinLoosersHypeMax.Enable(tf)
		self.parent.tourneamentPanel.spinLoosersHypeJumps.Enable(tf)
	
	def OnRadioSelect(self, event):
		if event.GetEventObject() is self.radioTorneio:
			self.set_tourneament(True)
			self.sel_type="tournament_select"
		elif event.GetEventObject() is self.radioAUE:
			self.set_tourneament(False)
			self.sel_type="stochastic_universal_sampling_select"
		elif event.GetEventObject() is self.radioRoleta:
			self.set_tourneament(False)
			self.sel_type="roulette_select"
		elif event.GetEventObject() is self.radioRanking:
			self.set_tourneament(False)
			self.sel_type="order_select_linear"
		elif event.GetEventObject() is self.radioRanking2:
			self.set_tourneament(False)
			self.sel_type="order_select_exponential"
			
			


	def GetValues(self):
		#valores tipo [selection_type, [range(arity), range(number_ppl), range(estocastic)] ] ... ultimos 2 sao vazios se  selection_type!="tournament_select"
		arity = val_to_list(self.spinArityMin.GetValue(),self.spinArityMax.GetValue(),self.spinArityJumps.GetValue())
		if self.sel_type=="tournament_select":
			fighters = val_to_list(self.parent.tourneamentPanel.spinFightersMin.GetValue(),
							self.parent.tourneamentPanel.spinFightersMax.GetValue(),
							self.parent.tourneamentPanel.spinFightersJumps.GetValue())
			# needs to be a decimal
			looser = val_to_list(self.parent.tourneamentPanel.spinLoosersHypeMin.GetValue(),
							self.parent.tourneamentPanel.spinLoosersHypeMax.GetValue(),
							self.parent.tourneamentPanel.spinLoosersHypeJumps.GetValue())
			looser =map(to_float,looser)
			return [self.sel_type, arity, fighters, looser, [None]]
		elif self.sel_type=="order_select_linear" or self.sel_type=="order_select_exponential":
			lol = val_to_list(self.spinHightProbMin.GetValue(),
							self.spinHightProbMax.GetValue(),
							self.spinHightProbJumps.GetValue())
			lol = map(to_float,lol)
			return [self.sel_type, arity ,[None], [None], lol]
		else:
			return [self.sel_type, arity ,[None], [None], [None]]


class TourneamentPanel(wx.Panel):
	def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER, name=wx.PanelNameStr,stuf_list=[-1]):
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		### Participant number ###
		box = wx.StaticBox(self, -1,"Number of Contestants", pos=(0, 5), size=(348, 90))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,32,125,17)						# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)				# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])			# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])			# size reference to sp1, 50 is the sizeX needed for this one
		s3=(s1[0]+6,s1[1]+s1[3]+s1[1]/2+4,70,s1[3])	# in the other line - you go down by adding the size of the text and delta (in this case 4 (cause of the spins) and half of the line1 position)  to the first line position
		sp3=(s3[0]+s3[2],s3[1]-2,50,sp1[3])			#equal to sp2
		
		if stuf_list[0]!="tournament_select":
			d,a,j = 2,2,0
		else:
			d,a,j = list_to_val(stuf_list[2])
		
		wx.StaticText(self, -1, "Number of Contestants:", pos=(s1[0],s1[1]))
		self.spinFightersMin = wx.SpinCtrl(self, -1, "2", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinFightersMin.SetRange(1,999)
		self.spinFightersMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinFightersMax = wx.SpinCtrl(self, -1, "2", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinFightersMax.SetRange(1,999)
		self.spinFightersMax.SetValue(a)
		wx.StaticText(self, -1, "with step:", pos=(s3[0],s3[1]))
		self.spinFightersJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinFightersJumps.SetRange(0,999)
		self.spinFightersJumps.SetValue(j)
		
		### Loosers hype ###
		wx.StaticBox(self, -1,"Stochastic Tournament", pos=(0,105), size=(348, 90))
		
		# same stuf as above ...
		s1=(10,132,200,17)
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)
		s2=(sp1[0]+sp1[2]+20,s1[1],12,s1[3])
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])
		s3=(s1[0]+6,s1[1]+s1[3]+13+4,70,s1[3])
		sp3=(s3[0]+s3[2],s3[1]-2,50,sp1[3])
		
		if stuf_list[0]!="tournament_select":
			d,a,j = 0,0,0
		else:
			d,a,j = map(to_int,list_to_val(stuf_list[3]))
		
		wx.StaticText(self, -1, "Losers Hype:", pos=(s1[0],s1[1]))
	
		self.spinLoosersHypeMin = wx.SpinCtrl(self, -1, "0", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinLoosersHypeMin.SetRange(0,100)
		self.spinLoosersHypeMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinLoosersHypeMax = wx.SpinCtrl(self, -1, "2", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinLoosersHypeMax.SetRange(0,100)
		self.spinLoosersHypeMax.SetValue(a)
		wx.StaticText(self, -1, "with step:", pos=(s3[0],s3[1]))
		self.spinLoosersHypeJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinLoosersHypeJumps.SetRange(0,100)
		self.spinLoosersHypeJumps.SetValue(j)
		

class RecombinationPanel(wx.Panel):
	def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER, name=wx.PanelNameStr,stuf_list=[-1]):
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		self.parent=parent #bah ...!
		self.sel_type=stuf_list[0]
		
		## TIPO RECOMBINACAO
		box = wx.StaticBox(self, -1, "Method", pos=(0, 0), size=(348, 118))
		
		self.radioUmPonto = wx.RadioButton(self, -1, "One Point Crossover", style = wx.RB_GROUP, pos=(10, 19))
		self.radioNPontos = wx.RadioButton(self, -1, "N Points Crossover", pos=(10, 42))
		self.radioUniforme = wx.RadioButton(self, -1, "Uniform Crossover", pos=(10, 65))
		#self.radioMediaPonderada = wx.RadioButton(self, -1, "Weighted Average Crossover", pos=(10, 88))
		
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioUmPonto)
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioNPontos)
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioUniforme)
		#self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioMediaPonderada)
		
		if self.sel_type=="one_point_crossover":
			self.radioUmPonto.SetValue(True)
			self.set_cross(False,False)
		if self.sel_type=="npoint_crossover":
			self.radioNPontos.SetValue(True)
			self.set_cross(True,False)
		if self.sel_type=="uniform_crossover":
			self.radioUniforme.SetValue(True)
			self.set_cross(False,False)
		#if self.sel_type=="whole_arithmetic_crossover":
			#self.radioMediaPonderada.SetValue(True)
			#self.set_cross(False,True)

		### PROBABILIDADE DE RECOMBINACAO###
		box = wx.StaticBox(self, -1,"Crossover Probabality (%)", pos=(0, 123), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,123+27,17,17)				# pos initial, sizeY is the default, 27 is the distance to the StaticBox
		sp1=(s1[0]+s1[2],s1[1]-2,55,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],55,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		#valores tipo  ##crossover = [callable_string, range(prob), range(numPoints), range(weight)]
		d,a,j = map(to_int,list_to_val(stuf_list[1]))
		
		wx.StaticText(self, -1, "From", pos=(s1[0],s1[1]))
		self.spinRecProbMin = wx.SpinCtrl(self, -1, "70", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinRecProbMin.SetRange(0,100)
		self.spinRecProbMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinRecProbMax = wx.SpinCtrl(self, -1, "70", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinRecProbMax.SetRange(0,100)
		self.spinRecProbMax.SetValue(a)
		wx.StaticText(self, -1, "with step:", pos=(s3[0],s3[1]))
		self.spinRecProbJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinRecProbJumps.SetRange(0,100)
		self.spinRecProbJumps.SetValue(j)
		

	def OnRadioSelect(self, event):
		if event.GetEventObject() is self.radioUmPonto:
			self.set_cross(False,False)
			self.sel_type = "one_point_crossover"
		if event.GetEventObject() is self.radioNPontos:
			self.set_cross(True,False)
			self.sel_type = "npoint_crossover"
		if event.GetEventObject() is self.radioUniforme:
			self.set_cross(False,False)
			self.sel_type = "uniform_crossover"
		#if event.GetEventObject() is self.radioMediaPonderada:
			#self.set_cross(False,True)
			#self.sel_type = "whole_arithmetic_crossover"
	
	
	def set_cross(self,corte,peso):
		self.parent.recombinationParametersPanel.spinCutPointsMin.Enable(corte)
		self.parent.recombinationParametersPanel.spinCutPointsMax.Enable(corte)
		self.parent.recombinationParametersPanel.spinCutPointsJumps.Enable(corte)
		self.parent.recombinationParametersPanel.spinWeightMin.Enable(peso)
		self.parent.recombinationParametersPanel.spinWeightMax.Enable(peso)
		self.parent.recombinationParametersPanel.spinWeightJumps.Enable(peso)

	def GetValues(self):
		#valores tipo  ##crossover = [callable_string, range(prob), range(numPoints), range(weight)]
		prob = map(to_float,val_to_list(self.spinRecProbMin.GetValue(),self.spinRecProbMax.GetValue(),self.spinRecProbJumps.GetValue()))
		#if self.sel_type=="whole_arithmetic_crossover":
			#peso = val_to_list(self.parent.recombinationParametersPanel.spinWeightMin.GetValue(),
							#self.parent.recombinationParametersPanel.spinWeightMax.GetValue(),
							#self.parent.recombinationParametersPanel.spinWeightJumps.GetValue())
		#else:
		peso=[None]
		if self.sel_type=="npoint_crossover":
			npoints= val_to_list(self.parent.recombinationParametersPanel.spinCutPointsMin.GetValue(),
							self.parent.recombinationParametersPanel.spinCutPointsMax.GetValue(),
							self.parent.recombinationParametersPanel.spinCutPointsJumps.GetValue())
		else:
			npoints= [None]
		return [self.sel_type, prob,npoints, peso]
		

class RecombinationParametersPanel(wx.Panel):
	def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER, name=wx.PanelNameStr,stuf_list=[-1]):
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		### N POINTS CORTE ###
		box = wx.StaticBox(self, -1,"Number of Cut Points", pos=(0, 5), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,5+27,17,17)				# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		if stuf_list[0]!="npoint_crossover":
			d,a,j = 2,2,0
		else:
			d,a,j = list_to_val(stuf_list[2])
		
		wx.StaticText(self, -1, "From", pos=(s1[0],s1[1]))
		self.spinCutPointsMin = wx.SpinCtrl(self, -1, "2", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinCutPointsMin.SetRange(0,100)
		self.spinCutPointsMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinCutPointsMax = wx.SpinCtrl(self, -1, "2", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinCutPointsMax.SetRange(0,100)
		self.spinCutPointsMax.SetValue(a)
		wx.StaticText(self, -1, "with step:", pos=(s3[0],s3[1]))
		self.spinCutPointsJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinCutPointsJumps.SetRange(0,100)
		self.spinCutPointsJumps.SetValue(j)
		
		
		### PESO (WTF) ###
		#box = wx.StaticBox(self, -1,"Peso", pos=(0, 80), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,90+27,17,17)				# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		if stuf_list[0]!="whole_arithmetic_crossover":
			d,a,j = 0,0,0
		else:
			d,a,j = list_to_val(stuf_list[3])
		
		wx.StaticText(self, -1, "From", pos=(s1[0],s1[1]))
		self.spinWeightMin = wx.SpinCtrl(self, -1, "2", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinWeightMin.SetRange(0,100)
		self.spinWeightMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinWeightMax = wx.SpinCtrl(self, -1, "2", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinWeightMax.SetRange(0,100)
		self.spinWeightMax.SetValue(a)
		wx.StaticText(self, -1, "with step:", pos=(s3[0],s3[1]))
		self.spinWeightJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinWeightJumps.SetRange(0,100)
		self.spinWeightJumps.SetValue(j)
		


class MutationPanel(wx.Panel):
	def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER, name=wx.PanelNameStr,stuf_list=[-1],ag=True):
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		self.sel_type=stuf_list[0]
		self.ag= ag
		
		## METODO MUTATAR
		box = wx.StaticBox(self, -1, "Method", pos=(0, 0), size=(348, 125))
		
		self.radioUmBit = wx.RadioButton(self, -1, "1 Bit Mutation", style = wx.RB_GROUP, pos=(10, 19))
		self.radioNBits = wx.RadioButton(self, -1, "N Bits Mutation", pos=(10, 42))
		self.radioPosicao = wx.RadioButton(self, -1, "Position Related Bit Mutation", pos=(10, 65))
		
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioUmBit)
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioNBits)
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioPosicao)
		
		
		## ALFA
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(35,65+27,40,17)				# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		#valores tipo  ##Mutation = [ (callable), range(Prob), range(alpha), range(sigma)]
		if stuf_list[0]!="flip_bits_position_related_mutation":
			d,a,j = 1,1,0
		else:
			d,a,j = list_to_val(stuf_list[2])
		
		wx.StaticText(self, -1, "Alpha", pos=(s1[0],s1[1]))
		self.spinAlfaMin = wx.SpinCtrl(self, -1, "", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinAlfaMin.SetRange(-999,999)
		self.spinAlfaMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinAlfaMax = wx.SpinCtrl(self, -1, "", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinAlfaMax.SetRange(-999,999)
		self.spinAlfaMax.SetValue(a)
		wx.StaticText(self, -1, "with step:", pos=(s3[0],s3[1]))
		self.spinAlfaJumps = wx.SpinCtrl(self, -1, "", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinAlfaJumps.SetRange(0,999)
		self.spinAlfaJumps.SetValue(j)
		
		if self.sel_type=="flip_one_bit_mutation":
			self.radioUmBit.SetValue(True)
			self.set_mut(False)
		if self.sel_type=="flip_several_bits_mutation":
			self.radioNBits.SetValue(True)
			self.set_mut(False)
		if self.sel_type=="flip_bits_position_related_mutation":
			self.radioPosicao.SetValue(True)
			self.set_mut(True)
		
		
		### PROBABILIDADE DE MUTACAO###
		box = wx.StaticBox(self, -1,"Mutation Probability (%)", pos=(0, 130), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,130+27,17,17)				# pos initial, sizeY is the default, 27 is the distance to the StaticBox
		sp1=(s1[0]+s1[2],s1[1]-2,55,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],55,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		#valores tipo  ##Mutation = [ (callable), range(Prob), range(alpha), range(sigma)]
		
		if self.sel_type!="flip_bits_position_related_mutation":
			d,a,j = map(to_int,list_to_val(stuf_list[1])) #put the 0.xx in xx%
		else:
			d,a,j = 5,5,0
		
		wx.StaticText(self, -1, "From", pos=(s1[0],s1[1]))
		self.spinMutProbMin = wx.SpinCtrl(self, -1, "", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinMutProbMin.SetRange(0,100)
		self.spinMutProbMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinMutProbMax = wx.SpinCtrl(self, -1, "", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinMutProbMax.SetRange(0,100)
		self.spinMutProbMax.SetValue(a)
		wx.StaticText(self, -1, "with step:", pos=(s3[0],s3[1]))
		self.spinMutProbJumps = wx.SpinCtrl(self, -1, "", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinMutProbJumps.SetRange(0,100)
		self.spinMutProbJumps.SetValue(j)
		
		
		if not ag: ##"EE"
			
			### SIGMA ###
			box = wx.StaticBox(self, -1,"Evolutionary Estrategies Probabilities (%)", pos=(0, 201), size=(348, 66))
			
			# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
			# they refere to the pos and size of other objects to make thier owns
			s1=(10,201+27,50,17)				# pos initial, sizeY is the default
			sp1=(s1[0]+s1[2],s1[1]-2,55,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
			s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
			sp2=(s2[0]+s2[2],sp1[1],55,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
			s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
			sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
			
			#d,a,j = map(to_int,list_to_val(stuf_list[3])) #put the 0.xx in xx%
			if stuf_list[3]!=[None]:
				d,a,j = map(to_int,list_to_val(stuf_list[3])) #put the 0.xx in xx%
			else:
				d,a,j = 5,5,0
			
			wx.StaticText(self, -1, "Sigma of", pos=(s1[0],s1[1]))
			self.spinSigmaMin = wx.SpinCtrl(self, -1, "", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
			self.spinSigmaMin.SetRange(0,100)
			self.spinSigmaMin.SetValue(d)
			wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
			self.spinSigmaMax = wx.SpinCtrl(self, -1, "", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
			self.spinSigmaMax.SetRange(0,100)
			self.spinSigmaMax.SetValue(a)
			wx.StaticText(self, -1, "with step of:", pos=(s3[0],s3[1]))
			self.spinSigmaJumps = wx.SpinCtrl(self, -1, "", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
			self.spinSigmaJumps.SetRange(0,100)
			self.spinSigmaJumps.SetValue(j)
		

	def set_mut(self,tf):
		self.spinAlfaMin.Enable(tf)
		self.spinAlfaMax.Enable(tf)
		self.spinAlfaJumps.Enable(tf)
	
	def OnRadioSelect(self,event):
		if event.GetEventObject() is self.radioUmBit:
			self.sel_type = "flip_one_bit_mutation"
			self.set_mut(False)
		if event.GetEventObject() is self.radioNBits:
			self.sel_type = "flip_several_bits_mutation"
			self.set_mut(False)
		if event.GetEventObject() is self.radioPosicao:
			self.sel_type = "flip_bits_position_related_mutation"
			self.set_mut(True)

	def GetValues(self):
		#valores tipo  ##Mutation = [ (callable), range(Prob), range(alpha), range(sigma)]
		prob = val_to_list(self.spinMutProbMin.GetValue(),self.spinMutProbMax.GetValue(),self.spinMutProbJumps.GetValue())
		prob = map(to_float,prob)
		
		if self.sel_type=="flip_bits_position_related_mutation":
			alfas = val_to_list(self.spinAlfaMin.GetValue(),self.spinAlfaMax.GetValue(),self.spinAlfaJumps.GetValue())
		else:
			alfas = [None]
		
		if not self.ag:
			sigmas = val_to_list(self.spinSigmaMin.GetValue(),self.spinSigmaMax.GetValue(),self.spinSigmaJumps.GetValue())
			sigmas = map(to_float,sigmas)
		else:
			sigmas = [None]
		return [self.sel_type, prob, alfas, sigmas]


class SurvivorSelectionPanel(wx.Panel):
	def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER, name=wx.PanelNameStr,stuf_list=[-1]):
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		self.sel_type=stuf_list[0]
		
		box = wx.StaticBox(self, -1, "Method", pos=(0, 0), size=(348, 155))
		
		self.radioFitness = wx.RadioButton(self, -1, "Fitness Chomp", style = wx.RB_GROUP, pos=(10, 19))
		self.radioGerational = wx.RadioButton(self, -1, "Gerational", pos=(10, 42))
		self.radioBestWorst = wx.RadioButton(self, -1, "Best Worst", pos=(10, 65))
		
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioFitness)
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioGerational)
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioBestWorst)
		
		
		## POP DIV
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(20,65+27,70,17)				# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		#valores tipo  ##SurvivorSelection = [string (callable), range(elitism), range(pop_div), range(best_pass)]
		#ss="chomp_select", "gerational_select", 
		
		if stuf_list[0]!="best_worst_select":
			d,a,j = 0,0,0
		else:
			d,a,j = map(to_int,list_to_val(stuf_list[2]))
		
		wx.StaticText(self, -1, "% Pop Bests", pos=(s1[0],s1[1]))
		self.spinPopDivMin = wx.SpinCtrl(self, -1, "", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinPopDivMin.SetRange(0,100)
		self.spinPopDivMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinPopDivMax = wx.SpinCtrl(self, -1, "", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinPopDivMax.SetRange(0,100)
		self.spinPopDivMax.SetValue(a)
		wx.StaticText(self, -1, "with stpe of", pos=(s3[0],s3[1]))
		self.spinPopDivJumps = wx.SpinCtrl(self, -1, "", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinPopDivJumps.SetRange(0,100)
		self.spinPopDivJumps.SetValue(j)
		
		
		## BEST PASS
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(20,93+27,70,17)				# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		#valores tipo  ##SurvivorSelection = [string (callable), range(elitism), range(pop_div), range(best_pass)]
		#ss="chomp_select", "gerational_select", 
		if stuf_list[0]!="best_worst_select":
			d,a,j = 0,0,0
		else:
			d,a,j = map(to_int,list_to_val(stuf_list[3]))
		
		wx.StaticText(self, -1, "% Bests Pass", pos=(s1[0],s1[1]))
		self.spinBestPassMin = wx.SpinCtrl(self, -1, "", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinBestPassMin.SetRange(0,100)
		self.spinBestPassMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinBestPassMax = wx.SpinCtrl(self, -1, "", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinBestPassMax.SetRange(0,100)
		self.spinBestPassMax.SetValue(a)
		wx.StaticText(self, -1, "with step:", pos=(s3[0],s3[1]))
		self.spinBestPassJumps = wx.SpinCtrl(self, -1, "", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinBestPassJumps.SetRange(0,100)
		self.spinBestPassJumps.SetValue(j)
		
		
		### ELITISMO ###
		box = wx.StaticBox(self, -1,"Elitism Elements", pos=(0, 160), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,160+27,17,17)				# pos initial, sizeY is the default, 27 is the distance to the StaticBox
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		if stuf_list[0]=="best_worst_select":
			d,a,j = 0,0,0
		else:
			d,a,j = list_to_val(stuf_list[1])
				
		wx.StaticText(self, -1, "From", pos=(s1[0],s1[1]))
		self.spinLeetMin = wx.SpinCtrl(self, -1, "", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		self.spinLeetMin.SetRange(0,100)
		self.spinLeetMin.SetValue(d)
		wx.StaticText(self, -1, "to", pos=(s2[0],s2[1]))
		self.spinLeetMax = wx.SpinCtrl(self, -1, "", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		self.spinLeetMax.SetRange(0,100)
		self.spinLeetMax.SetValue(a)
		wx.StaticText(self, -1, "with step:", pos=(s3[0],s3[1]))
		self.spinLeetJumps = wx.SpinCtrl(self, -1, "", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		self.spinLeetJumps.SetRange(0,100)
		self.spinLeetJumps.SetValue(j)
		
		
		if self.sel_type=="chomp_select":
			self.radioFitness.SetValue(True)
			self.set_elitism(True)
		if self.sel_type=="gerational_select":
			self.radioGerational.SetValue(True)
			self.set_elitism(True)
		if self.sel_type=="best_worst_select":
			self.radioBestWorst.SetValue(True)
			self.set_elitism(False)

	def set_elitism(self,tf):
		self.spinLeetMin.Enable(tf)
		self.spinLeetMax.Enable(tf)
		self.spinLeetJumps.Enable(tf)
		self.spinPopDivMin.Enable(not tf)
		self.spinPopDivMax.Enable(not tf)
		self.spinPopDivJumps.Enable(not tf)
		self.spinBestPassMin.Enable(not tf)
		self.spinBestPassMax.Enable(not tf)
		self.spinBestPassJumps.Enable(not tf)

	def OnRadioSelect(self,event):
		if event.GetEventObject() is self.radioFitness:
			self.sel_type = "chomp_select"
			self.set_elitism(True)
		if event.GetEventObject() is self.radioGerational:
			self.sel_type = "gerational_select"
			self.set_elitism(True)
		if event.GetEventObject() is self.radioBestWorst:
			self.sel_type = "best_worst_select"
			self.set_elitism(False)

	def GetValues(self):
		#valores tipo  ##SurvivorSelection = [string (callable), range(elitism), range(pop_div), range(best_pass)]
		if self.sel_type=="best_worst_select":
			elitism = [None]
			pop_div = val_to_list(self.spinPopDivMin.GetValue(),self.spinPopDivMax.GetValue(),self.spinPopDivJumps.GetValue())
			pop_div = map(to_float,pop_div)
			best_pass = val_to_list(self.spinBestPassMin.GetValue(),self.spinBestPassMax.GetValue(),self.spinBestPassJumps.GetValue())
			best_pass = map(to_float,best_pass)
		else:
			elitism = val_to_list(self.spinLeetMin.GetValue(),self.spinLeetMax.GetValue(),self.spinLeetJumps.GetValue())
			pop_div = [None]
			best_pass = [None]
		return [self.sel_type, elitism, pop_div, best_pass]
	
def list_to_val(list):
	"""From a list calculates from, to and jum"""
	if list==None:
		print "NONE is swaing arround ... :x"
		return None
	elif len(list)<1:
		sys.exit(1)
	elif len(list)!=1: #long
		if list[1]-list[0]!=0 and list[1]-list[0]<0.01:
			aux = 0.01
		else:
			aux = list[1]-list[0]
		return (list[0], list[-1], aux)
	else: #quick
		return (list[0], list[0], 0)


def val_to_list(f,t,j):
	"""From from, to and jum calculates the list"""
	if j==0 or f==t:
		return [f]
	else:
		list,i=[],0
		while i<=t-f:
			list.append(f+i)
			i+=j
	return list








	
	
	
	